Ext.onReady(function() {
    var currentUser = Ext.create('Ext.form.field.Text',{
            xtype: 'textfield',
            fieldLabel: str_chgpwd_currentuser,
            name: 'usr',
            maxLength : 20,
            minLength : 1,
            allowBlank : false,
            disabled: true
    });
    
    var msgLabel = Ext.create('Ext.form.Label', {
		text: ''
	});
    
    function getCurrentUser(){
        Ext.Ajax.request({
            url : getPath("/aa/po/userManager.do"),  
            params : {
                "md":"readCurrentUserId"
            },
            success : function(response) {  
                var ret = Ext.JSON.decode(response.responseText);
                if(ret.success){
                    currentUser.setValue(ret.msg);
                    curUserId = ret.msg;
                }
                else {
                    Ext.MessageBox.alert(str_common_error,ret.msg);
                }
            }
        });
    }
    
    var form = Ext.create('Ext.form.Panel', {
      fieldDefaults: {
          labelWidth: 80
      },
      defaultType: 'textfield',
      bodyPadding: 5,
      items: [currentUser,{
          fieldLabel: str_chgpwd_currentpwd,
          name: 'pwd',
          maxLength : 20,
          minLength : 1,
          inputType : 'password',
          allowBlank : false
      },{
          fieldLabel: str_chgpwd_nwepwd,
          name: 'newpwd',
          inputType : 'password',
          maxLength : 12,
          minLength : 6,
          allowBlank : false,
          validator: function(value) {
        	  var pwd = this.previousSibling('[name=pwd]');
              return (value === pwd.getValue()) ? str_chgpwd_newandoldsame : true;
          }
      },{
          fieldLabel: str_chgpwd_confnewpwd,
          name: 'confirmpwd',
          inputType : 'password',
          maxLength : 12,
          minLength : 6,
          allowBlank : false,
          validator: function(value) {
        	  var newpwd = this.previousSibling('[name=newpwd]');
        	  return (value === newpwd.getValue()) ? true : str_chgpwd_twopwdsame;
          }
      },{
          xtype: 'hiddenfield',
          name: 'md',
          value: 'changePassword'
      }, msgLabel]
    });
    
    var submitBtn = Ext.create('Ext.button.Button', {
        text: str_common_change,
        handler : function() {
        	submitBtn.setDisabled(true);
        	form.getForm().submit({
        		clientValidation: true,
        		method : 'POST',
        		url: getPath('/aa/po/userManager.do'),
        		success: function(form, action) {
        			msgLabel.setText(action.result.msg);
        			window.location.href = ctx;
        		},
        		failure: function(form, action) {
        			submitBtn.setDisabled(false);
        			msgLabel.setText(action.result.msg);
        		}
        	});
        }
    });
    
    var win = Ext.create('Ext.window.Window', {
        title: str_chgpwd_chgpwd,
        width: 280,
        height:210,
        iconCls: 'icon-lock',
        layout: 'fit',
        plain: true,
        closable   : false,
        collapsible: true,
        items: form,
        buttons: [submitBtn,{
            text: str_common_reset,
            handler : function() {
            	form.getForm().reset();
            	msgLabel.setText('');
            	getCurrentUser();
            }
        }]
    }).show();
    getCurrentUser();
});